from flask import Flask,jsonify,request,Blueprint,session
from common.res import (getRes,getErrorRes,getSuccessRes,getDataRes)
from common.sqlInjectionSecurity import sqlEscape,sqlEscapeField
from DAL.rechargeStatDAL import orderinfoDAL

recharge_order = Blueprint('recharge_order',__name__)

@recharge_order.route("/recharge_order/getlist",methods=['POST'])
def getlist():
    param = {
        'start': request.form.get('start') and sqlEscape(request.form.get('start')) or None,
        'end': request.form.get('end') and sqlEscape(request.form.get('end')) or None,
        'Game': request.form.get('Game') and sqlEscape(request.form.get('Game')) or None,
        'Chan': request.form.get('Chan') and sqlEscape(request.form.get('Chan')) or "",
        'Account': request.form.get('Account') and sqlEscape(request.form.get('Account')) or None,
        'RechargeAccount': request.form.get('RechargeAccount') and sqlEscape(request.form.get('RechargeAccount')) or None,
        'Server': request.form.get('Server') and sqlEscape(request.form.get('Server')) or None,
        'page': request.form.get('page') and sqlEscape(request.form.get('page')) or 1,
        'limit': request.form.get('limit') and sqlEscape(request.form.get('limit')) or 20,
        'filed': request.form.get('filed') and sqlEscape(request.form.get('filed')) or 'id',
        'sort': request.form.get('sort') and sqlEscape(request.form.get('sort')) or 'ascending'
          }
    dal = orderinfoDAL()
    data,count = dal.getList(**param)
    if data:
        res = getSuccessRes(data=data,count=count)
    else:
        res = getSuccessRes(data=[], count=count)
    return jsonify(res)

@recharge_order.route("/recharge_order/getlist4down",methods=['POST'])
def getlist4down():
    param = {
        'start': request.form.get('start') and sqlEscape(request.form.get('start')) or None,
        'end': request.form.get('end') and sqlEscape(request.form.get('end')) or None,
        'Game': request.form.get('Game') and sqlEscape(request.form.get('Game')) or None,
        'Chan': request.form.get('Chan') and sqlEscape(request.form.get('Chan')) or "",
        'Account': request.form.get('Account') and sqlEscape(request.form.get('Account')) or None,
        'RechargeAccount': request.form.get('RechargeAccount') and sqlEscape(request.form.get('RechargeAccount')) or None,
        'Server': request.form.get('Server') and sqlEscape(request.form.get('Server')) or None
          }
    dal = orderinfoDAL()
    data = dal.getlist4down(**param)
    if data:
        res = getSuccessRes(data=data)
    else:
        res = getSuccessRes(data=[])
    return jsonify(res)
